﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 运算符重载
{
    class OperatorOverloading
    {
        static void Main(string[] args)
        {
            ComplexNumber x, y;
            double real, imaginary;
            try
            {
                Console.WriteLine("Enter the real part of complex number:");
                real = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Enter the imaginary part of complex number:");
                imaginary = Convert.ToDouble(Console.ReadLine());

                x = new ComplexNumber(real, imaginary);

                Console.WriteLine("Enter the real part of complex number:");
                real = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Enter the imaginary part of complex number:");
                imaginary = Convert.ToDouble(Console.ReadLine());

                y = new ComplexNumber(real, imaginary);
                
                Console.WriteLine("{0} + {1} = {2}", x, y, x + y);
                Console.WriteLine("{0} - {1} = {2}", x, y, x - y);
                Console.WriteLine("{0} * {1} = {2}", x, y, x * y);
            }
            catch (FormatException expection)
            {
                Console.WriteLine(expection.Message);
            }
            catch
            {
                Console.WriteLine("出现异常");
            }

            Console.ReadKey();
        }//end method Main
    }
}
